package com.aiit.mapper;

import com.aiit.annotation.AutoFill;
import com.aiit.dto.UserLoginDTO;
import com.aiit.entity.TeaOrder;
import com.aiit.entity.User;
import com.aiit.entity.UserAddress;
import com.aiit.enumeration.OperationType;
import com.aiit.result.PageResult;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    @Insert("insert into user(username,password,id_number,create_time,update_time,create_user,update_user)" +
            "values" +
            "(#{username},#{password},#{idNumber},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @AutoFill(value = OperationType.INSERT)
    void insert(User user);

    @Select("select * from user where username = #{username}")
    User getByUsername(String username);

    @Select("select * from user where username = #{username}")
    PageResult selectVIP(UserLoginDTO userLoginDTO);

    @Select("select * from address where username = #{username}")
    UserAddress getByUserAddressname(String username);

    @AutoFill(value = OperationType.UPDATE)
    void update(UserAddress userAddress);

    @Insert("insert into address(username,address,create_time,update_time,create_user,update_user)" +
            "values" +
            "(#{username},#{address},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @AutoFill(value = OperationType.INSERT)
    void insertAddress(UserAddress userAddress);

    @Select("select * from orders where username = #{username}")
    List<TeaOrder> getByTeaOrder(String username);

    @AutoFill(value = OperationType.UPDATE)
    Long getById(Long id);

    @Select("select * from orders where id = #{id}")
    TeaOrder getByTeaOrderDetail(Long id);

    @AutoFill(value = OperationType.UPDATE)
    void payment(TeaOrder teaOrder);

}
